function matd = rslice_time2matd ( ocean_time, base_date )
% RSLICE_TIME2MATD:  convert netcdf times to matlab-native times
%
% PARAMETERS:
% Input:
%     ocean_time:
%         all time instances as read from the netcdf file(s)
%     base_date:
%         the units string from the netcdf file(s)
% Output:
%     matd:
%         matlab datenum equivalents of all the ocean time values.
%         This depends upon correctly parsing the units string.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Name: rslice-0_9_2 $
% $Id: rslice_time2matd.m,v 1.1 2005/12/30 18:17:30 jevans Exp $
% AUTHOR:  johnevans@acm.org
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%







[time_units,r] = strtok ( base_date, ' ' );
[since,some_date] = strtok ( r, ' ' );
matd = [];
if length(some_date) > 0
	[f,date_token_count] = sscanf ( some_date, '%f-%f-%f %f:%f:%f' );
	if ( date_token_count == 6 )
		matd = datenum ( f(1), f(2), f(3), f(4), f(5), f(6) );
		switch ( time_units )
		case 'days'
			matd = matd + ocean_time;
		case 'hours'
			matd = matd + ocean_time/24;
		case 'minutes'
			matd = matd + ocean_time/1440;
		case 'seconds'
			matd = matd + ocean_time/86400;
		otherwise
			msg = sprintf ( '%s:  unhandled time units %s.\n', mfilename, time_units );
			rslice_warning ( msg );
		end
	else
		msg = sprintf ( '%s:  did not read 6 values from %s.\n', mfilename, some_date );
		rslice_warning ( msg );

	end
else
	msg = sprintf ( '%s:  could not parse %s.\n', mfilename, base_date );
	rslice_warning ( msg );
end


return;
